package testDemo.Thread.ProducerAndCustomer;

public class Box {
    private int milk;
    private boolean steta=false;

    public synchronized void put(int milk){
        if(steta){
            try {
                wait();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        this.milk =this.milk + milk;
        System.out.println("送奶工送来"+milk+"瓶牛奶");

        steta=true;
        notifyAll();
    }
    public synchronized void get(int milk){
        if(!steta){
            try {
                wait();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        this.milk =this.milk - milk;
        System.out.println("用户拿取"+milk+"瓶牛奶");
        steta=false;
        notifyAll();

    }
    public int size(){
        return milk;
    }

}
